home *** CD-ROM | disk | FTP | other *** search
- /*
- * Selectors.c
- *
- * WASTE PROJECT
- * WEGetInfo / WESetInfo
- *
- * Copyright (c) 1993-1994 Marco Piovanelli
- * All Rights Reserved
- *
- */
-
- #ifndef _WASTE_use_68k_asm_
- #define _WASTE_use_68k_asm_ 1L
- #endif
-
- #define weUndefinedSelectorErr -50 /* paramErr */
-
- #define FIELD_OFFSET(FIELD, STRUCT) (short) &((STRUCT *) 0L)->FIELD
- #define FIELD_SIZE(FIELD, STRUCT) (short) sizeof(((STRUCT *) 0L)->FIELD)
- #define FIELD_DESC(FIELD, STRUCT) { FIELD_OFFSET(FIELD, STRUCT), FIELD_SIZE(FIELD, STRUCT) }
-
- typedef struct WEFieldDescriptor {
- short fOffset;
- short fLength;
- } WEFieldDescriptor;
-
- typedef struct WELookupTable {
- OSType selector;
- WEFieldDescriptor desc;
- } WELookupTable;
-
- pascal void _WELookupSelector(/*const*/ WELookupTable *table, OSType selector, WEFieldDescriptor *desc);
- pascal OSErr _WEGetField(/*const*/ WELookupTable *table, OSType selector, long *info, void *structure);
- pascal OSErr _WESetField(/*const*/ WELookupTable *table, OSType selector, long *info, void *structure);
-
- typedef struct LongRect {
- long top;
- long left;
- long bottom;
- long right;
- } LongRect;
-
- typedef struct WERec { /* version 1.1a4 */
- GrafPtr port;
- Handle hText;
- Handle hLines;
- Handle hStyles;
- Handle hRuns;
- long textLength;
- long nLines;
- long nStyles;
- long nRuns;
- LongRect viewRect;
- LongRect destRect;
- long selStart;
- long selEnd;
- unsigned long flags;
- long caretTime;
- long clickTime;
- long clickLoc;
- long anchorStart;
- long anchorEnd;
- ProcPtr clickLoop;
- char unused1;
- char clickEdge;
- char unused2;
- char firstByte;
- GrafPtr offscreenPort;
- RgnHandle viewRgn;
- ProcPtr scrollProc;
- short clickCount;
- char alignment;
- long refCon;
- Ptr tsmReference;
- long tsmAreaStart;
- long tsmAreaEnd;
- ProcPtr tsmPreUpdate;
- ProcPtr tsmPostUpdate;
- long currentDrag;
- long dragCaretOffset;
- ProcPtr translateDragHook;
- Handle hActionStack;
- long modCount;
- /* WERunAttributes nullStyle; */
- } WERec;
-
- WELookupTable _WEMainSelectorTable[] = {
- { 'clik', FIELD_DESC(clickLoop, WERec) },
- { 'drag', FIELD_DESC(currentDrag, WERec) },
- { 'line', FIELD_DESC(hLines, WERec) },
- { 'port', FIELD_DESC(port, WERec) },
- { 'post', FIELD_DESC(tsmPostUpdate, WERec) },
- { 'pre ', FIELD_DESC(tsmPreUpdate, WERec) },
- { 'refc', FIELD_DESC(refCon, WERec) },
- { 'runa', FIELD_DESC(hRuns, WERec) },
- { 'scrl', FIELD_DESC(scrollProc, WERec) },
- { 'styl', FIELD_DESC(hStyles, WERec) },
- { 'text', FIELD_DESC(hText, WERec) },
- { 'tsmd', FIELD_DESC(tsmReference, WERec) },
- { 'xdrg', FIELD_DESC(translateDragHook, WERec) },
- { 0, 0, 0 }};
-
- typedef struct WEOHTableElement {
- OSType objectType;
- ProcPtr newHandler;
- ProcPtr freeHandler;
- ProcPtr drawHandler;
- ProcPtr clickHandler;
- ProcPtr cursorHandler;
- } WEOHTableElement;
-
- WELookupTable _WEObjectHandlerSelectorTable[] = {
- { 'clik', FIELD_DESC(clickHandler, WEOHTableElement) },
- { 'curs', FIELD_DESC(cursorHandler, WEOHTableElement) },
- { 'draw', FIELD_DESC(drawHandler, WEOHTableElement) },
- { 'free', FIELD_DESC(freeHandler, WEOHTableElement) },
- { 'new ', FIELD_DESC(newHandler, WEOHTableElement) },
- { 0, 0, 0 }};
-
- pascal void _WELookupSelector(/*const*/ WELookupTable *table, OSType selector, WEFieldDescriptor *desc)
- {
-
- #if _WASTE_use_68k_asm_
-
- asm {
- move.l selector, d0 ; d0 = selector code to search
- move.l table, a0 ; a0 = start of table
- move.l desc, a1 ; a1 = ptr to desc variable
- clr.l (a1) ;
-
- @loop cmp.l (a0)+, d0 ; selector found?
- beq @found ;
- tst.l (a0)+ ; at the end of the table?
- bne.s @loop ;
- bra.s @exit ;
-
- @found move.l (a0), (a1) ; copy descriptor record
- @exit
- }
-
- #else
-
- for ( ; table->selector != selector ; table++ )
- if ( * (long *) &(table->desc) == 0L )
- break;
-
- *desc = table->desc;
-
- #endif
-
- }
-
- pascal OSErr _WEGetField(/*const*/ WELookupTable *table, OSType selector, long *info, void *structure)
- {
- WEFieldDescriptor desc;
-
- _WELookupSelector(table, selector, &desc);
-
- if (desc.fLength == 0)
- return weUndefinedSelectorErr;
-
- *info = * (long *) ((long) structure + desc.fOffset);
- return noErr;
- }
-
- pascal OSErr _WESetField(/*const*/ WELookupTable *table, OSType selector, long *info, void *structure)
- {
- WEFieldDescriptor desc;
-
- _WELookupSelector(table, selector, &desc);
-
- if (desc.fLength == 0)
- return weUndefinedSelectorErr;
-
- * (long *) ((long) structure + desc.fOffset) = *info;
- return noErr;
- }